<template>
  <div class="app-container">
    <!-- 按钮 -->
    <el-card class="search-card">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="buttonMethods(1)"
            v-hasPermi="['campus:unpaid:export']"
          >
            添加
          </el-button>
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
    </el-card>
    <!-- 列表 -->
    <el-card class="table-card">
      <el-table :data="dataList">
        <el-table-column label="标题名称" align="center" prop="idCardNumber" />
        <el-table-column label="折扣百分比" align="center" prop="idCardNumber" />
        <el-table-column label="备注" align="center" prop="idCardNumber" />
        <el-table-column label="使用状态" align="center" prop="idCardNumber" />
        <el-table-column label="创建人" align="center" prop="idCardNumber" />
        <el-table-column label="创建时间" align="center" prop="idCardNumber" />
        <el-table-column label="修改人" align="center" prop="idCardNumber" />
        <el-table-column label="修改时间" align="center" prop="idCardNumber" />
        <el-table-column label="操作" align="center" width="200px">
          <template slot-scope="scope">
            <el-button
              type="warning"
              size="mini"
              class="padding_4_10"
              @click="buttonMethods(1, scope.row)"
              v-hasPermi="['campus:grade:edit']"
              >修改</el-button
            >
            <el-button
              type="danger"
              size="mini"
              class="padding_4_10"
              @click="buttonMethods(4, scope.row)"
              v-hasPermi="['campus:grade:remove']"
              >删除
            </el-button>
            <el-button
              :type="scope.row.status == 1 ? 'danger' : 'success'"
              size="mini"
              class="padding_4_10"
              @click="buttonMethods(5, scope.row)"
              v-hasPermi="['campus:grade:remove']"
            >
              <span v-if="scope.row.status == 1">停用</span>
              <span v-if="scope.row.status == 2">启用</span>
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!--  -->
    <el-dialog :title="title" :visible.sync="open" width="40%" append-to-body>
      <el-form ref="form" :model="queryForm" label-width="95px">
        <el-row>
          <el-col :span="14">
            <el-form-item label="标题名称" prop="gradeId" style="width: 100%">
              <el-select
                v-model="queryParams.gradeId"
                placeholder="请选择标题名称"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in gradeList"
                  :key="index"
                  :value="item.id"
                  :label="item.gradeName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="折扣百分比" prop="gradeName" class="is-required">
              <el-input v-model="queryForm.gradeName" placeholder="请输入折扣百分比">
                <template slot="append"
                  >折扣值：0-100之间（100表示无折扣；0表示免费）</template
                >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="gradeName">
              <el-input
                v-model="queryForm.gradeName"
                placeholder="请输入备注"
                maxlength="200"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="buttonMethods(2)">确 定</el-button>
        <el-button @click="buttonMethods(3)">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { listGrade } from "@/api/campus/grade";
import { listClassManage } from "@/api/campus/classManage";

export default {
  name: "studentdiscount",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 1,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      dataList: [
        {
          status: 1,
          name: "1",
        },
        {
          name: "2",
          status: 2,
        },
      ],
      campusList: [],
      gradeList: [],
      queryForm: {},
    };
  },
  created() {},
  activated() {},
  methods: {
    // 列表
    getList() {},
    /**
     * 按钮操作的方法
     *
     * @param options 操作选项，用于区分不同的按钮操作
     * @param value 按钮值
     */
    buttonMethods(options, value) {
      // 添加 修改
      if (options == 1) {
        if (value) {
          this.title = "修改";
          this.queryForm = { ...value };
          this.open = true;
        } else {
          this.title = "添加";
          this.queryForm = {};
          this.open = true;
        }
      }
      // 提交
      else if (options == 2) {
        var data = { ...this.queryForm };
        console.log(data);
      }
      // 关闭弹框
      else if (options == 3) {
        this.title = "";
        this.queryForm = {};
        this.open = false;
      }
      // 删除
      else if (options == 4) {
        this.$confirm("此操作将永久删除餐别, 是否继续?", "删除", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {})
          .catch(() => {});
      }
      // 关闭 开启
      else if (options == 5) {
        var str = value.status == 1 ? "停用" : "启用";
        this.$confirm("此操作将" + str + "餐别, 是否继续?", str, {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {})
          .catch(() => {});
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 导出
    handleExport() {
      this.download(
        "",
        {
          ...this.queryParams,
        },
        `餐别管理导出.xlsx`
      );
    },
  },
};
</script>
<style>
.padding_4_10 {
  padding: 4px 10px !important;
}

.el-upload--picture-card {
  width: 90px !important;
  height: 90px !important;
  line-height: 90px !important;
}
</style>
